﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace psafth.RCTiming.Main
{
    class ArduinoBoard
    {
        #region Private declarations

        private static SerialPort _SerialPort;          //Serial port
        private const int _Baudrate = 9600;             //Baud-Rate of the serial port (must be the same value on Arduino Serial.begin-Method

        #endregion

        internal static void SoundHorn(int duration)
        {
            try
            {
                _SerialPort = new SerialPort(Properties.Settings.Default.SerialPort) { BaudRate = _Baudrate };
                _SerialPort.Open();
                _SerialPort.Write(string.Format("{0}\n", duration));
                _SerialPort.Close();
            }
            catch (Exception)
            {
                // Catch every exception. If something is wrong the race must go on.
            }
        }
    }

}
